package com.ying.rabbitmqspringbootproducer.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: RabbitMQConfig
 * Package: com.ying.rabbitmqspringbootproducer.config
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/5/29 10:42
 * @Version 1.0
 */



@Configuration
public class RabbitMQConfig {
    public static final String EXCHANGE_NAME = "topicExchange";
    public static final String QUEUE_USER_NAME = "topicUserQueue";
    public static final String QUEUE_PAY_NAME = "topicPayQueue";

    //定义交换机
    @Bean
    public Exchange exchange() {
        return new TopicExchange(EXCHANGE_NAME, true, false,null);
    }

    //定义队列
    @Bean
    public Queue topicUserQueue() {
        return new Queue(QUEUE_USER_NAME, true, false, false,null);
    }

    //定义队列
    @Bean
    public Queue topicPayQueue() {
        return new Queue(QUEUE_PAY_NAME, true, false, false,null);
    }

    //绑定队列
    @Bean
    public Binding bindingTopicUserQueue(Queue topicUserQueue, @Qualifier("exchange") Exchange topicExchange) {
//        return new Binding()
        return BindingBuilder.bind(topicUserQueue).to(topicExchange).with("user.*").noargs();
    }

    //绑定队列
    @Bean
    public Binding bindingTopicPayQueue(Queue topicPayQueue, @Qualifier("exchange") Exchange topicExchange) {
        return BindingBuilder.bind(topicPayQueue).to(topicExchange).with("pay.*").noargs();
    }

}
